import request from "@/utils/request";
import type {PwdResetForm, SysUserQuery, SysUserType} from "@/types/system";

const baseUrl = '/system/user';

export function getPageList(query: SysUserQuery, current = 1, size = 20) {
    return request({
        url: `${baseUrl}/search`,
        method: 'POST',
        data: { ...query, current, size},
    })
}

export function deleteById(id: string) {
    return request({
        url: `${baseUrl}/${id}`,
        method: 'DELETE',
    });
}

export function add(data: SysUserType) {
    return request({
        url: `${baseUrl}`,
        method: 'POST',
        data,
    });
}

export function update(data: SysUserType) {
    return request({
        url: `${baseUrl}`,
        method: 'PUT',
        data,
    });
}

export function detailsId(id: string) {
    return request({
        url: `${baseUrl}/${id}`,
        method: 'GET',
    });
}

export function checkExist(params: {username: string} | {mobile: string}) {
    return request({
        url: `${baseUrl}/exist`,
        method: 'GET',
        params,
    });
}

export function updatePassword(data: PwdResetForm) {
    return request({
        url: `${baseUrl}/password`,
        method: 'PUT',
        data,
    });
}


export function getCurrUserInfo() {
    return request({
        url: `${baseUrl}/getCurrUserInfo`,
        method: 'GET',
    });
}

export function getCurrPermByRoleIds(roleIds: string) {
    return request({
        url: `/menu/userInfo/getCurrPermByRoleIds`,
        method: 'GET',
        params: { roleIds }
    });
}
